package io.netty.handler.traffic;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import io.netty.channel.ChannelHandler;

/**
 * 统计字节流,AbstractTrafficShapingHandler的默认实现貌似有一堆问题,后续版本需要持续关注
 */
@ChannelHandler.Sharable
public class GlobalByteTrafficMonitor extends GlobalTrafficShapingHandler {

	void createGlobalTrafficCounter(ScheduledExecutorService executor) {
		if (executor == null) {
			throw new NullPointerException("executor");
		}
		TrafficCounterExt tc = new TrafficCounterExt(this, executor, "GlobalTC", checkInterval);
		setTrafficCounter(tc);
		tc.start();
	}

	public GlobalByteTrafficMonitor(ScheduledExecutorService executor, long checkInterval) {
		super(executor, checkInterval);
	}

	public GlobalByteTrafficMonitor() {
		this(Executors.newSingleThreadScheduledExecutor(), DEFAULT_CHECK_INTERVAL);
	}

	public TrafficCounter getTrafficCounter() {
		return trafficCounter;
	}
}
